﻿using SDF.Data.Mapping;
using SDF.Plugin.Misc.DynamicEntity.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SDF.Plugin.Misc.DynamicEntity.Data.Map
{
    public class DynamicEntityItemMap : SDFEntityTypeConfiguration<DynamicEntityItem>
    {
        public DynamicEntityItemMap()
        {
            this.ToTable("DynamicEntityItem");
            this.HasKey(t => t.Id);
            this.Property(t => t.CodeName).IsRequired().HasMaxLength(255);
            this.Property(t => t.Name).IsRequired().HasMaxLength(255);
            this.Property(t => t.DefaultValue).HasMaxLength(2500);

            this.HasRequired(bc => bc.Header)
                .WithMany(bp => bp.Fields)
                .HasForeignKey(bc => bc.HeaderId);

            //对于一个表中，两个字段都需要设置外键级联删除或更新的，只能设置一个字段，另一个字段必须通过其他方式处理
            this.HasOptional(t => t.ReferenceEntity).WithOptionalDependent(t => t.ReferBy).WillCascadeOnDelete(false);
        }
    }
}